<template>
    <div class="DemoForm">
        <el-date-picker
                v-model="newValue"
                type="datetime"
                value-format="yyyy-MM-dd"
                placeholder="选择日期" v-if="['date','datetime'].includes(formType) && (typeof(dictionaryId)=== 'undefined' || dictionaryId == null ||  dictionaryId === '')"
                :disabled="formDisabled === 'true'">
        </el-date-picker>
        <el-input
                v-if="['varchar','int','bigint','float','double'].includes(formType) && (typeof(dictionaryId)=== 'undefined' || dictionaryId == null ||  dictionaryId === '')"
                placeholder="请输入内容"
                v-model="newValue"
                :disabled="formDisabled === 'true'">
        </el-input>
        <el-select
                v-if="typeof(dictionaryId) !== 'undefined' && dictionaryId != null && dictionaryId !== ''"
                placeholder="请选择"
                v-model="newValue"
                :disabled="formDisabled === 'true'">
            <el-option
                    v-for="item in options"
                    :key="item[selectObject.param4]"
                    :label="item[selectObject.param4]"
                    :value="item[selectObject.param4]">
            </el-option>
        </el-select>
    </div>
</template>

<script>
    export default {
        props: {
            value: [String,Number,Date],
            formType: String ,  // int date datetime varchar
            formDisabled: String,
            dictionaryId: [Number,String],
            selectObject: Object
        },
        data() {
          return {
              // url: 'dictionary',
              options: [{
                  value: '选项1',
                  label: '黄金糕'
              }, {
                  value: '选项2',
                  label: '双皮奶'
              }, {
                  value: '选项3',
                  label: '蚵仔煎'
              }, {
                  value: '选项4',
                  label: '龙须面'
              }, {
                  value: '选项5',
                  label: '北京烤鸭'
              }]
          }
        },
        mounted(){
            this.initDictionaryData()
        },
        methods: {
            initDictionaryData(){
                if (this.dictionaryId !== null && this.dictionaryId !== ''){
                    console.log(`初始化字典:${this.dictionaryId}`)
                    let obj = JSON.parse(this.selectObject.param5)
                    this.$api.commonData.dataList(this.selectObject.param2,obj).then(res => {
                        this.options = res.data.data
                        console.log(`接收dictionary数据 >>>`,res)
                    })
                }
            }
        },
        computed: {
            newValue: {
                get(){
                    return this.value;
                },
                set:function (value) {
                    console.log('set value >>',value)
                    this.$emit('input',value)
                }
            }
        }
    };
</script>
